package com.hyj.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hyj.entity.Sections;
import com.hyj.entity.Teachers;
import com.hyj.service.SecService;
import com.hyj.service.TeaService;




@Controller
public class TeaController {
	@Autowired
	private SecService SecService;
	@Autowired
	private TeaService teaService;
	
	/**
	 * 全查教师
	 * @param TeaEntity
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/getTea")
	public Object getTea(Teachers tea) {
		List<Teachers> list = teaService.getTea(tea);
		tea.setPage(null);
		tea.setLimit(null);
		Map<String, Object> map = new HashMap<String, Object>();
		System.out.println("查得到教师全部数据" + list);
		List<Teachers> list2 = teaService.getTea(tea);
		map.put("code", 0);
		map.put("msg", "教师列表");
		map.put("count", list2.size()); 
		map.put("data", list);
		return map;
	}
	@RequestMapping("/getTeaSec")
	public Object getTeaSec(ModelMap map) {
		List<Sections> list =SecService.getSec(null) ;
		map.put("getTeaDep",list);
		return "teaList";


	}
	/**
	 * 添加教师方法
	 * @param t
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/addTea")
	public Object addTea(Teachers t) {
		int tea = teaService.addTea(t);
		System.out.println("拿到的添加的教师数据" + t);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("msg", "教师添加");
		map.put("count", 100); 
		map.put("data", tea); 
		return map;
	}
	/**
	 * 删除教师方法
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/delTea")
	public Object delTea (Integer TId) {
		System.out.println("拿到删除教师ID:"+TId);
		int tea=teaService.delTea(TId);
		System.out.println("拿到删除后教师的信息："+tea);
		return tea;
	}
	/**
	 * 修改教师方法
	 * @param t
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/updateTea")
	public Object updateTea(Teachers TId) {
		int tea =teaService.updateTea(TId);
		System.out.println("拿到修改教师信息的数据："+TId);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("msg", "教师修改");
		map.put("count", 100); 
		map.put("data", tea); 
		return map;
	}
	
	
	
}
